package me.yuzho.study.concurrency;

import java.util.concurrent.Callable;

/** 有返回值的任务
 * @author yzhou-citrix
 *
 */
public class TaskWithResult implements Callable<String> {
    
    private int id;
    
    public TaskWithResult(int id) {
        this.id = id;
    }
    
    protected int countDown = 10;

    @Override
    public String call() throws Exception {
        
        while(countDown-- > 0) {
            //Thread.yield();
            try {
                Thread.sleep((long) (1000*Math.random()));
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return String.format("Result of TaskWithResult %d", id);
    }

}
